package com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_adapter2;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.example.qingyiapp.R;
import com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_bean.JavaBean_lv2;

import java.util.List;

public class adapter_address_lv2 extends BaseAdapter {

    List<JavaBean_lv2.DataBean> data;
    Context context;

    public adapter_address_lv2(List<JavaBean_lv2.DataBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        MyViewHolder myViewHolder = null;

        if(convertView==null){
            myViewHolder = new MyViewHolder();
            convertView = View.inflate(context, R.layout.address_rows2,null);

            myViewHolder.recyclerView = convertView.findViewById(R.id.address_rv2);

            convertView.setTag(myViewHolder);
        }else{
            myViewHolder = (MyViewHolder) convertView.getTag();
        }

        adapter_address_lv2_rv2 adapter_address_lv2_rv2 = new adapter_address_lv2_rv2(data,context);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);

        myViewHolder.recyclerView.setLayoutManager(linearLayoutManager);
        myViewHolder.recyclerView.setAdapter(adapter_address_lv2_rv2);

        return convertView;
    }

    class MyViewHolder{
        RecyclerView recyclerView;
    }

}
